﻿using Microsoft.Extensions.DependencyInjection;
using System;
using System.Diagnostics;

namespace IOC
{
    public class Class1
    {
        public interface IAccount{}
        public interface IMessage { }
        public interface ITool { }
        public class Account : Base,IAccount { }
        public class Message : Base, IMessage { }
        public class Tool : Base, ITool { }

        public class Base
        {
            public Base()
            {
                Console.WriteLine($"{GetType().Name}已经创建");
            }
        }

        public static void Run()
        {
            var provider = new ServiceCollection()
                .AddTransient<Base, Account>()
                .AddScoped<Base, Message>()
                .AddSingleton<Base, Tool>()
                .BuildServiceProvider();

            Debug.Assert(provider.GetService<IAccount>() is Account);
            Debug.Assert(provider.GetService<IMessage>() is Message);
            Debug.Assert(provider.GetService<ITool>() is Tool);
        }

    }
}
